#!/bin/bash
menu(){
echo -e "\t\e[1;31msinger menu\e[0m"
echo -e "\n\t\e[1;32m1.display singer\e[0m"
echo -e "\n\t\e[1;32m2.choose singing\e[0m"
echo -e "\n\t\e[1;32m3.exit\e[0m"
echo -n -e "\nplease input your option:";read option

singer=(`cat singer.txt`)
songs=(`cat songslist.txt`)
num=`cat singer.txt|wc -w`
song_num=`cat songslist.txt|wc -w`
}

while :
do 
menu
case $option in

1)
        echo -e "the singer lists as follows:\e[33m${singer[@]}\e[0m,total is: \e[32m$num\033[0m"
        echo -e "the songs we can chosed as follows:\e[33m${songs[@]}\e[0m,total is: \e[32m$song_num\033[0m"
        ;;
2)
        singer=(`cat singer.txt`)
        songs=(`cat songslist.txt`)
        length=${#singer[@]}
        lucky_num=$((RANDOM%length))
        song_len=${#songs[@]}
        song_lucky_num=$(( RANDOM%song_len ))
        echo -e "\e[1;35mThe chosen singer and the song to sing:\e[0m"
        for i in {3..1}
        do
                echo -e "\t\e[45;34m$i\e[0m" 
                sleep 1
        done
        echo -e  "please singer \e[1;31m${singer[lucky_num]}\e[0m sing for us \e[1;32m${songs[song_lucky_num]}\e[0m" 
        unset singer[lucky_num]
        echo ${singer[@]} >singer.txt
        unset songs[song_lucky_num]
        echo ${songs[@]} >songslist.txt
        echo -e "\n\e[46;31m no singing singer are:${singer[@]}\e[0m"
        num=`cat singer.txt |wc -w`
        echo -e "\n\e[46;31mno singing songs are: ${songs[@]}\e[0m"
	if (( num==0 ));then
                read -p "now all singer already sang,again" again
                cp singer_ex.txt  singer.txt
                read -p "now songs will restart!"
                cp songslist_ex.txt songslist.txt
        fi
        ;;
3)
        exit
        ;;
*)
	exit
	;;
esac
done
